
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>014_邮件发送 · 瑕家瑾轩_Note</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="xiajiajinxuan">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-page-toc-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-auto-scroll-table/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="015_转义字符.html" />
    
    
    <link rel="prev" href="013_死锁.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../001_git教程/001_安装配置.html">
            
                <a href="../001_git教程/001_安装配置.html">
            
                    
                    001_git教程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../001_git教程/001_安装配置.html">
            
                <a href="../001_git教程/001_安装配置.html">
            
                    
                    001_安装配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../001_git教程/002_git常用语句及流程.html">
            
                <a href="../001_git教程/002_git常用语句及流程.html">
            
                    
                    002_git常用语句及流程
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../002_gitbook教程/001_安装配置及使用.html">
            
                <a href="../002_gitbook教程/001_安装配置及使用.html">
            
                    
                    002_gitbook教程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../002_gitbook教程/001_安装配置及使用.html">
            
                <a href="../002_gitbook教程/001_安装配置及使用.html">
            
                    
                    001_安装配置及使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../002_gitbook教程/002_生成文件目录.html">
            
                <a href="../002_gitbook教程/002_生成文件目录.html">
            
                    
                    002_生成文件目录
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../003_typora/001_typora-markdown语法.html">
            
                <a href="../003_typora/001_typora-markdown语法.html">
            
                    
                    003_typora
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../003_typora/001_typora-markdown语法.html">
            
                <a href="../003_typora/001_typora-markdown语法.html">
            
                    
                    001_typora-markdown语法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="001_ORACLE关键字执行顺序.html">
            
                <a href="001_ORACLE关键字执行顺序.html">
            
                    
                    004_Oracle
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="001_ORACLE关键字执行顺序.html">
            
                <a href="001_ORACLE关键字执行顺序.html">
            
                    
                    001_ORACLE关键字执行顺序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="002_关键字_between.html">
            
                <a href="002_关键字_between.html">
            
                    
                    002_关键字_between
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="003_数据库启停.html">
            
                <a href="003_数据库启停.html">
            
                    
                    003_数据库启停
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="004_http请求.html">
            
                <a href="004_http请求.html">
            
                    
                    004_http请求
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="005_NULL处理.html">
            
                <a href="005_NULL处理.html">
            
                    
                    005_NULL处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="006_交集_并集_差集.html">
            
                <a href="006_交集_并集_差集.html">
            
                    
                    006交集并集_差集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="007_字符处理.html">
            
                <a href="007_字符处理.html">
            
                    
                    007_字符处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="008_字符排序.html">
            
                <a href="008_字符排序.html">
            
                    
                    008_字符排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.9" data-path="009_定时任务.html">
            
                <a href="009_定时任务.html">
            
                    
                    009_定时任务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.10" data-path="010_数字处理.html">
            
                <a href="010_数字处理.html">
            
                    
                    010_数字处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.11" data-path="011_序列流水号.html">
            
                <a href="011_序列流水号.html">
            
                    
                    011_序列流水号
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.12" data-path="012_时间日期处理.html">
            
                <a href="012_时间日期处理.html">
            
                    
                    012_时间日期处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.13" data-path="013_死锁.html">
            
                <a href="013_死锁.html">
            
                    
                    013_死锁
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5.14" data-path="014_邮件发送.html">
            
                <a href="014_邮件发送.html">
            
                    
                    014_邮件发送
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.15" data-path="015_转义字符.html">
            
                <a href="015_转义字符.html">
            
                    
                    015_转义字符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.16" data-path="016_触发器.html">
            
                <a href="016_触发器.html">
            
                    
                    016_触发器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.17" data-path="017_同义词.html">
            
                <a href="017_同义词.html">
            
                    
                    017_同义词
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.18" data-path="018_json解析.html">
            
                <a href="018_json解析.html">
            
                    
                    018_json解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.19" data-path="019_文件读写.html">
            
                <a href="019_文件读写.html">
            
                    
                    019_文件读写
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.20" data-path="020_用户创建及授权.html">
            
                <a href="020_用户创建及授权.html">
            
                    
                    020_用户创建及授权
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.21" data-path="021_中文字符验证.html">
            
                <a href="021_中文字符验证.html">
            
                    
                    021_中文字符验证
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../005_EBS/001_ebs模块.html">
            
                <a href="../005_EBS/001_ebs模块.html">
            
                    
                    005_EBS
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../005_EBS/001_ebs模块.html">
            
                <a href="../005_EBS/001_ebs模块.html">
            
                    
                    001_ebs模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../005_EBS/002_API列表.html">
            
                <a href="../005_EBS/002_API列表.html">
            
                    
                    002_API列表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../005_EBS/003_FND_GLOBAL和FND_PROFILE.html">
            
                <a href="../005_EBS/003_FND_GLOBAL和FND_PROFILE.html">
            
                    
                    003_FND_GLOBAL和FND_PROFILE
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../005_EBS/004_IE相关设置.html">
            
                <a href="../005_EBS/004_IE相关设置.html">
            
                    
                    004_IE相关设置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../005_EBS/005_MOAC.html">
            
                <a href="../005_EBS/005_MOAC.html">
            
                    
                    005_MOAC
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../005_EBS/006_描述性弹性域.html">
            
                <a href="../005_EBS/006_描述性弹性域.html">
            
                    
                    006_描述性弹性域
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../005_EBS/007_编译.html">
            
                <a href="../005_EBS/007_编译.html">
            
                    
                    007_编译
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../005_EBS/008_界面数据查询.html">
            
                <a href="../005_EBS/008_界面数据查询.html">
            
                    
                    008_界面数据查询
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../005_EBS/009_获取当前lov查询语句.html">
            
                <a href="../005_EBS/009_获取当前lov查询语句.html">
            
                    
                    009_获取当前lov查询语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="../005_EBS/010_表后缀.html">
            
                <a href="../005_EBS/010_表后缀.html">
            
                    
                    010_表后缀
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.11" data-path="../005_EBS/011_银行.html">
            
                <a href="../005_EBS/011_银行.html">
            
                    
                    011_银行
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.12" data-path="../005_EBS/012_错误代码及解释.html">
            
                <a href="../005_EBS/012_错误代码及解释.html">
            
                    
                    012_错误代码及解释
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.13" data-path="../005_EBS/013_WEBADI.html">
            
                <a href="../005_EBS/013_WEBADI.html">
            
                    
                    013_WEBADI
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.14" data-path="../005_EBS/014_请求参数间影响.html">
            
                <a href="../005_EBS/014_请求参数间影响.html">
            
                    
                    014_请求参数间影响
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.15" data-path="../005_EBS/015_FNDLOAD.html">
            
                <a href="../005_EBS/015_FNDLOAD.html">
            
                    
                    015_FNDLOAD
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.16" data-path="../005_EBS/016_配置文件.html">
            
                <a href="../005_EBS/016_配置文件.html">
            
                    
                    016_配置文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.17" data-path="../005_EBS/017_科目余额.html">
            
                <a href="../005_EBS/017_科目余额.html">
            
                    
                    017_科目余额
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.18" data-path="../005_EBS/018_供应商与客户.html">
            
                <a href="../005_EBS/018_供应商与客户.html">
            
                    
                    018_供应商与客户
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.19" data-path="../005_EBS/019_日记账.html">
            
                <a href="../005_EBS/019_日记账.html">
            
                    
                    019_日记账
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.20" data-path="../005_EBS/020_WebService发布与删除.html">
            
                <a href="../005_EBS/020_WebService发布与删除.html">
            
                    
                    020_WebService发布与删除
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.21" data-path="../005_EBS/021_报表开发.html">
            
                <a href="../005_EBS/021_报表开发.html">
            
                    
                    021_报表开发
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../006_FORM/001_数字格式设置.html">
            
                <a href="../006_FORM/001_数字格式设置.html">
            
                    
                    006_FORM
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../006_FORM/001_数字格式设置.html">
            
                <a href="../006_FORM/001_数字格式设置.html">
            
                    
                    001_数字格式设置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../006_FORM/002_Form状态.html">
            
                <a href="../006_FORM/002_Form状态.html">
            
                    
                    002_Form状态
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../006_FORM/003_窗口消息.html">
            
                <a href="../006_FORM/003_窗口消息.html">
            
                    
                    003_窗口消息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../006_FORM/004_Form环境配置.html">
            
                <a href="../006_FORM/004_Form环境配置.html">
            
                    
                    004_Form环境配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../006_FORM/005_打开窗口.html">
            
                <a href="../006_FORM/005_打开窗口.html">
            
                    
                    005_打开窗口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../006_FORM/006_日历LOV.html">
            
                <a href="../006_FORM/006_日历LOV.html">
            
                    
                    006_日历LOV
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.7" data-path="../006_FORM/007_form系统变量.html">
            
                <a href="../006_FORM/007_form系统变量.html">
            
                    
                    007_form系统变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.8" data-path="../006_FORM/008_层级与安全.html">
            
                <a href="../006_FORM/008_层级与安全.html">
            
                    
                    008_层级与安全
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.9" data-path="../006_FORM/009_item间关联.html">
            
                <a href="../006_FORM/009_item间关联.html">
            
                    
                    009_item间关联
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.10" data-path="../006_FORM/010_FORM界面数字百分比显示.html">
            
                <a href="../006_FORM/010_FORM界面数字百分比显示.html">
            
                    
                    010_FORM界面数字百分比显示
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../007_工具/001_ASCLL对照表.html">
            
                <a href="../007_工具/001_ASCLL对照表.html">
            
                    
                    007_工具
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../007_工具/001_ASCLL对照表.html">
            
                <a href="../007_工具/001_ASCLL对照表.html">
            
                    
                    001_ASCLL对照表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../007_工具/002_HTML转义字符.html">
            
                <a href="../007_工具/002_HTML转义字符.html">
            
                    
                    002_HTML转义字符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../007_工具/003_HTTP CONTENT_TYPE.html">
            
                <a href="../007_工具/003_HTTP CONTENT_TYPE.html">
            
                    
                    003_HTTP CONTENT_TYPE
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../007_工具/004_HTTP状态码详解.html">
            
                <a href="../007_工具/004_HTTP状态码详解.html">
            
                    
                    004_HTTP状态码详解
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >014_邮件发送</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="&#x4E00;&#x3001;&#x6587;&#x672C;&#x5F62;&#x5F0F;">&#x4E00;&#x3001;&#x6587;&#x672C;&#x5F62;&#x5F0F;</h2>
<pre><code class="lang-plsql">DECLARE
  p_recipient VARCHAR2(100) := &apos;fan.yang09@hand-china.com&apos;; -- &#x90AE;&#x4EF6;&#x63A5;&#x6536;&#x4EBA;
  p_subject   VARCHAR2(100) := &apos;&#x90AE;&#x4EF6;&#x6807;&#x9898;&apos;; -- &#x90AE;&#x4EF6;&#x6807;&#x9898;
  p_message   VARCHAR2(100) := &apos;&#x90AE;&#x4EF6;&#x6B63;&#x6587;&apos;; -- &#x90AE;&#x4EF6;&#x6B63;&#x6587;
  v_mailhost VARCHAR2(30) := &apos;smtp.163.com&apos;; --SMTP&#x670D;&#x52A1;&#x5668;&#x5730;&#x5740;
  v_user     VARCHAR2(30) := &apos;xxxx@163.com&apos;; --&#x767B;&#x5F55;SMTP&#x670D;&#x52A1;&#x5668;&#x7684;&#x7528;&#x6237;&#x540D;
  v_pass     VARCHAR2(20) := &apos;xxxx&apos;; --&#x767B;&#x5F55;SMTP&#x670D;&#x52A1;&#x5668;&#x7684;&#x5BC6;&#x7801;
  v_sender   VARCHAR2(50) := &apos;xxxx@163.com&apos;; --&#x53D1;&#x9001;&#x8005;&#x90AE;&#x7BB1;

  v_conn         utl_smtp.connection; --&#x5230;&#x90AE;&#x4EF6;&#x670D;&#x52A1;&#x5668;&#x7684;&#x8FDE;&#x63A5;
  v_msg          VARCHAR2(4000); --&#x90AE;&#x4EF6;&#x5185;&#x5BB9;
  v_characterest VARCHAR2(400);
BEGIN
  v_conn := utl_smtp.open_connection(v_mailhost,
                                     25);
  utl_smtp.ehlo(v_conn,
                v_mailhost); --&#x662F;&#x7528; ehlo() &#x800C;&#x4E0D;&#x662F; helo() &#x51FD;&#x6570;
  --&#x5426;&#x5219;&#x4F1A;&#x62A5;&#xFF1A;ORA-29279: SMTP &#x6C38;&#x4E45;&#x6027;&#x9519;&#x8BEF;: 503 5.5.2 Send hello first.

  utl_smtp.command(v_conn,
                   &apos;AUTH LOGIN&apos;); -- smtp&#x670D;&#x52A1;&#x5668;&#x767B;&#x5F55;&#x6821;&#x9A8C;
  utl_smtp.command(v_conn,
                   utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw(v_user))));
  utl_smtp.command(v_conn,
                   utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw(v_pass))));

  utl_smtp.mail(v_conn,
                v_sender); --&#x8BBE;&#x7F6E;&#x53D1;&#x4EF6;&#x4EBA;
  utl_smtp.rcpt(v_conn,
                p_recipient); --&#x8BBE;&#x7F6E;&#x6536;&#x4EF6;&#x4EBA;

  -- &#x521B;&#x5EFA;&#x8981;&#x53D1;&#x9001;&#x7684;&#x90AE;&#x4EF6;&#x5185;&#x5BB9; &#x6CE8;&#x610F;&#x62A5;&#x5934;&#x4FE1;&#x606F;&#x548C;&#x90AE;&#x4EF6;&#x6B63;&#x6587;&#x4E4B;&#x95F4;&#x8981;&#x7A7A;&#x4E00;&#x884C;
  v_msg := &apos;Date:&apos; || to_char(SYSDATE,
                              &apos;dd mon yy hh24:mi:ss&apos;) || utl_tcp.crlf || &apos;From: &apos; || &apos;&lt;&apos; || v_sender || &apos;&gt;&apos; || utl_tcp.crlf || &apos;To: &apos; || &apos;&lt;&apos; ||
           p_recipient || &apos;&gt;&apos; || utl_tcp.crlf || &apos;Subject: &apos; || p_subject || utl_tcp.crlf || utl_tcp.crlf -- &#x8FD9;&#x524D;&#x9762;&#x662F;&#x62A5;&#x5934;&#x4FE1;&#x606F;
           || p_message; -- &#x8FD9;&#x4E2A;&#x662F;&#x90AE;&#x4EF6;&#x6B63;&#x6587;

  utl_smtp.open_data(v_conn); --&#x6253;&#x5F00;&#x6D41;

  --&#x5C06;&#x7CFB;&#x7EDF;&#x7F16;&#x7801;&#x8F6C;&#x4E3A;GBK&#xFF0C;&#x6839;&#x636E;&#x90AE;&#x7BB1;&#xFF0C;&#x4E0D;&#x4E00;&#x5B9A;&#x8F6C;
  --&#x83B7;&#x53D6;&#x7CFB;&#x7EDF;&#x7F16;&#x7801;
  SELECT ndp.value
    INTO v_characterest
    FROM nls_database_parameters ndp
   WHERE ndp.parameter = &apos;NLS_CHARACTERSET&apos;;
  --&#x7F16;&#x7801;&#x8F6C;&#x6362;
  v_msg := convert(v_msg,
                   &apos;ZHS16GBK&apos;,
                   v_characterest);
  utl_smtp.write_raw_data(v_conn,
                          utl_raw.cast_to_raw(v_msg)); --&#x8FD9;&#x6837;&#x5199;&#x6807;&#x9898;&#x548C;&#x5185;&#x5BB9;&#x90FD;&#x80FD;&#x7528;&#x4E2D;&#x6587;
  utl_smtp.close_data(v_conn); --&#x5173;&#x95ED;&#x6D41;
  utl_smtp.quit(v_conn); --&#x5173;&#x95ED;&#x8FDE;&#x63A5;

EXCEPTION
  WHEN OTHERS THEN
    dbms_output.put_line(&apos;&#x9519;&#x8BEF;&#x4EE3;&#x7801;&apos; || SQLCODE); --&#x5F53;&#x524D;&#x4F1A;&#x8BDD;&#x6267;&#x884C;&#x72B6;&#x6001;&#xFF0C;&#x9519;&#x8BEF;&#x7F16;&#x7801;
    dbms_output.put_line(&apos;&#x9519;&#x8BEF;&#x4FE1;&#x606F;&apos; || SQLERRM); --&#x5F53;&#x524D;&#x9519;&#x8BEF;&#x4FE1;&#x606F;
END;
</code></pre>
<h2 id="&#x4E8C;&#x3001;html&#x5F62;&#x5F0F;">&#x4E8C;&#x3001;HTML&#x5F62;&#x5F0F;</h2>
<p>&#x90AE;&#x4EF6;&#x4E5F;&#x652F;&#x6301;html&#x7F16;&#x7801;&#xFF0C;&#x9700;&#x8981;&#x5728;&#x62A5;&#x5934;&#x4FE1;&#x606F;&#x4E2D;&#x58F0;&#x660E;Content-Type:text/html;charset=GBK&#xFF0C;&#x800C;HTML&#x4E2D;&#x4E5F;&#x80FD;&#x76F4;&#x63A5;&#x8F93;&#x6587;&#x672C;&#xFF0C;&#x8FD8;&#x53EF;&#x4EE5;&#x8FDB;&#x884C;&#x6837;&#x5F0F;&#x7F8E;&#x5316;&#xFF0C;&#x56E0;&#x6B64;&#x5EFA;&#x8BAE;&#x76F4;&#x63A5;&#x7528;&#x65B9;&#x5F0F;&#x4E8C;&#x4EE3;&#x66FF;&#x65B9;&#x5F0F;&#x4E00;</p>
<pre><code class="lang-plsql">/*
version:
date:2019-10-21 10:15:05
update by:fan.yang09@hand-china.com
utl_tcp.crlf&#xFF1A;&#x56DE;&#x8F66;&#x7B26;&#x548C;&#x6362;&#x884C;&#x7B26;
SMTP&#x5927;&#x5C0F;&#x9650;&#x5236;&#xFF1A;
user&#xFF1A;&#x7528;&#x6237;&#x540D;&#x6700;&#x5927;64&#x4E2A;&#x5B57;&#x7B26;
domain&#xFF1A;&#x57DF;&#x540D;&#x6700;&#x5927;64&#x4E2A;&#x5B57;&#x7B26;
&#x6700;&#x5927;&#x6536;&#x4EF6;&#x4EBA;&#xFF1A;100
text line&#xFF1A;&#x6700;&#x5927;1000&#x4E2A;&#x5B57;&#x7B26;&#xFF0C;&#x53EF;&#x7528;utl_tcp.crlf&#x6362;&#x884C;
*/
DECLARE
  p_recipient    VARCHAR2(100) := &apos;fan.yang09@hand-china.com&apos;; -- &#x90AE;&#x4EF6;&#x63A5;&#x6536;&#x4EBA; 
  p_subject      VARCHAR2(100) := &apos;&#x90AE;&#x4EF6;&#x6807;&#x9898;&#x4E00;&apos;; -- &#x90AE;&#x4EF6;&#x6807;&#x9898;
  p_message      VARCHAR2(20000) := &apos;&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;meta http-equiv=&quot;Content-Language&quot; content=&quot;zh-cn&quot;&gt;&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html;charset=UTF-8&quot;&gt;&lt;title&gt;excel-html&#x6A21;&#x677F;&lt;/title&gt;&lt;style&gt;.format{mso-number-format:&quot;\@&quot;}&lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;H1 align=&quot;center&quot;&gt;&lt;font size=&quot;5&quot;&gt;&#x5E94;&#x4ED8;&#x8D26;&#x9F84;&#x62A5;&#x8868;&lt;/font&gt;&lt;/H1&gt;&lt;TABLE border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;250&quot;&gt;&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;b&gt;&#x4E1A;&#x52A1;&#x5B9E;&#x4F53;&#xFF1A;&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&#x6C49;&#x5F97;&#x4FE1;&#x606F;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;b&gt;&#x622A;&#x6B62;&#x65E5;&#x671F;&#xFF1A;&lt;/b&gt;&lt;/td&gt;&lt;td Class=&quot;format&quot;&gt;$TEXT002$&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;b&gt;&#x6253;&#x5370;&#x65E5;&#x671F;&#xFF1A;&lt;/b&gt;&lt;/td&gt;&lt;td Class=&quot;format&quot;&gt;$TEXT004$&lt;/td&gt;&lt;/tr&gt;&lt;/TABLE&gt;&lt;TABLE width=&quot;100%&quot; border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tr bgcolor=&quot;#BBBBBB&quot;&gt;&lt;td nowrap align=&quot;center&quot; rowspan=&quot;2&quot;&gt;&#x5360;&#x4E24;&#x884C;&#x7684;&#x884C;&#x6807;&#x9898;&lt;/td&gt;&lt;td nowrap align=&quot;center&quot; rowspan=&quot;2&quot;&gt;&#x5360;&#x4E24;&#x884C;&#x7684;&#x884C;&#x6807;&#x9898;&lt;/td&gt;&lt;td nowrap align=&quot;center&quot; colspan=&quot;3&quot;&gt;&#x5360;&#x4E00;&#x884C;&#x4E09;&#x5217;&#x7684;&#x884C;&#x6807;&#x9898;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td nowrap align=&quot;left&quot;&gt;&#x7B2C;&#x4E00;&#x5217;&lt;/td&gt;&lt;td nowrap align=&quot;left&quot;&gt;&#x7B2C;&#x4E8C;&#x5217;&lt;/td&gt;&lt;td nowrap align=&quot;left&quot;&gt;&#x7B2C;&#x4E09;&#x5217;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td nowrap align=&quot;left&quot;&gt;$&#x503C;$&lt;/td&gt;&lt;td nowrap align=&quot;left&quot;&gt;$&#x503C;$&lt;/td&gt;&lt;td nowrap align=&quot;left&quot;&gt;$&#x503C;$&lt;/td&gt;&lt;td nowrap align=&quot;left&quot;&gt;$&#x503C;$&lt;/td&gt;&lt;td nowrap align=&quot;left&quot; class=&quot;format&quot;&gt;$&#x503C;$&lt;/td&gt;&lt;/tr&gt;&lt;/TABLE&gt;&lt;/body&gt;&lt;/html&gt;&apos;;
  v_mailhost     VARCHAR2(30) := &apos;smtp.163.com&apos;; --SMTP&#x670D;&#x52A1;&#x5668;&#x5730;&#x5740;
  v_user         VARCHAR2(30) := &apos;yang597814597@163.com&apos;; --&#x767B;&#x5F55;SMTP&#x670D;&#x52A1;&#x5668;&#x7684;&#x7528;&#x6237;&#x540D;
  v_pass         VARCHAR2(20) := &apos;yang9618&apos;; --&#x767B;&#x5F55;SMTP&#x670D;&#x52A1;&#x5668;&#x7684;&#x5BC6;&#x7801;
  v_sender       VARCHAR2(50) := &apos;yang597814597@163.com&apos;; --&#x53D1;&#x9001;&#x8005;&#x90AE;&#x7BB1; 
  v_conn         utl_smtp.connection; --&#x5230;&#x90AE;&#x4EF6;&#x670D;&#x52A1;&#x5668;&#x7684;&#x8FDE;&#x63A5;
  v_characterest VARCHAR2(400);
  l_reply        utl_smtp.reply; --&#x56DE;&#x590D;&#x4FE1;&#x606F;

  --&#x91C7;&#x7528;&#x4E8C;&#x8FDB;&#x5236;&#x5199;&#x5165;&#xFF0C;&#x5E76;&#x8FDB;&#x884C;&#x5B57;&#x7B26;&#x8F6C;&#x6362;&#xFF0C;&#x9632;&#x6B62;&#x4E71;&#x7801;
  PROCEDURE send_header(NAME   IN VARCHAR2,
                        header IN VARCHAR2) AS
  BEGIN
    utl_smtp.write_raw_data(v_conn,
                            utl_raw.cast_to_raw(convert(NAME || &apos;: &apos; || header || utl_tcp.crlf,
                                                        &apos;ZHS16GBK&apos;)));
  END;
BEGIN
  --&#x82E5;html&#x5185;&#x5BB9;&#x8FC7;&#x957F;&#xFF0C;&#x53EF;&#x5C06;&#x7F13;&#x51B2;&#x9650;&#x5236;&#x53D6;&#x6D88;
  --dbms_output.enable(buffer_size =&gt; NULL);

  v_conn := utl_smtp.open_connection(v_mailhost,
                                     25);
  --&#x6253;&#x5F00;SMTP&#x8FDE;&#x63A5;
  v_conn := utl_smtp.open_connection(host                          =&gt; v_mailhost, --SMTP&#x670D;&#x52A1;&#x5668;&#x5730;&#x5740;
                                     port                          =&gt; 25, --&#x7AEF;&#x53E3;
                                     tx_timeout                    =&gt; NULL, --&#x7B49;&#x5F85;&#x65F6;&#x95F4;&#xFF0C;0&#x4E0D;&#x7B49;&#x5F85;&#xFF0C;null&#x4E00;&#x76F4;&#x7B49;&#x5F85;&#xFF0C;&#x5355;&#x4F4D;&#x79D2;
                                     wallet_path                   =&gt; NULL,
                                     wallet_password               =&gt; NULL,
                                     secure_connection_before_smtp =&gt; FALSE);

  --&#x8BC6;&#x522B;&#x53D1;&#x9001;&#x8005;&#x7684;&#x57DF;
  utl_smtp.ehlo(v_conn,
                v_mailhost);
  --&#x67E5;&#x770B;&#x8FD4;&#x56DE;&#x7C7B;&#x578B;&#x53D1;&#x73B0;&#xFF0C;helo()&#x8FD4;&#x56DE;&#x7684;&#x662F;&#x4E00;&#x6761;utl_smtp.reply&#x6D88;&#x606F;&#xFF0C;ehlo()&#x8FD4;&#x56DE;&#x7684;&#x662F;&#x591A;&#x6761;utl_smtp.reply&#x7EC4;&#x6210;&#x7684;&#x8868;&#x7C7B;&#x578B;replies
  --&#x7F51;&#x4E0A;&#x8BF4;&#x4F7F;&#x7528;helo()&#x4F1A;&#x62A5;&#x9519;&#xFF0C;&#x8BD5;&#x4E86;&#x4E00;&#x4E0B;&#xFF0C;&#x6211;&#x7684;&#x4F8B;&#x5B50;&#x6CA1;&#x62A5;&#x9519;&#xFF0C;&#x67E5;&#x770B;&#x8FD4;&#x56DE;&#x7C7B;&#x578B;&#x53D1;&#x73B0;&#xFF0C;helo()&#x8FD4;&#x56DE;&#x7684;&#x662F;&#x4E00;&#x6761;utl_smtp.reply&#x6D88;&#x606F;&#xFF0C;ehlo()&#x8FD4;&#x56DE;&#x7684;&#x662F;&#x591A;&#x6761;utl_smtp.reply&#x7EC4;&#x6210;&#x7684;&#x8868;&#x7C7B;&#x578B;replies
  --&#x4E24;&#x8005;&#x529F;&#x80FD;&#x90FD;&#x662F;&#x5B9E;&#x73B0;&#x521D;&#x6B21;&#x63E1;&#x624B;&#xFF0C;&#x4E0D;&#x8FC7;ehlo&#x8FD4;&#x56DE;&#x7684;&#x6D88;&#x606F;&#x66F4;&#x591A;&#xFF0C;&#x4E3A;&#x4E86;&#x4FDD;&#x9669;&#xFF0C;&#x5EFA;&#x8BAE;&#x8FD8;&#x662F;&#x4F7F;&#x7528;ehlo

  --&#x6267;&#x884C;smtp&#x547D;&#x4EE4; &#x767B;&#x5F55;-&#x8F93;&#x5165;&#x8D26;&#x53F7;-&#x5BC6;&#x7801;
  utl_smtp.command(v_conn,
                   &apos;AUTH LOGIN&apos;); -- smtp&#x670D;&#x52A1;&#x5668;&#x767B;&#x5F55;&#x6821;&#x9A8C;
  utl_smtp.command(v_conn,
                   utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw(v_user))));
  utl_smtp.command(v_conn,
                   utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw(v_pass))));

  --&#x6307;&#x5B9A;&#x53D1;&#x4EF6;&#x4EBA;
  utl_smtp.mail(v_conn,
                v_sender);

  --&#x6307;&#x5B9A;&#x6536;&#x4EF6;&#x4EBA;
  utl_smtp.rcpt(v_conn,
                p_recipient);

  --&#x6253;&#x5F00;&#x6D41;&#xFF0C;&#x5199;&#x5165;&#x90AE;&#x4EF6;&#x6B63;&#x6587;
  utl_smtp.open_data(v_conn);

  --&#x5199;&#x5165;&#x6B63;&#x6587; write_data&#x548C;write_raw_data&#xFF0C;&#x53EF;&#x591A;&#x6B21;&#x8C03;&#x7528; &#x540C;&#x65F6;&#x8FDB;&#x884C;&#x5B57;&#x7B26;&#x8F6C;&#x6362;&#xFF0C;&#x9632;&#x6B62;&#x4E71;&#x7801;&#xFF0C;&#x6CE8;&#x610F;&#x6DFB;&#x52A0;&#x56DE;&#x8F66;&#x6362;&#x884C;&#x7B26;utl_tcp.crlf

  send_header(&apos;From&apos;,
              v_sender);
  send_header(&apos;To&apos;,
              p_recipient);
  send_header(&apos;Subject&apos;,
              p_subject);
  send_header(&apos;Content-Type&apos;,
              &apos;text/html;charset=GBK&apos;);

  --&#x6CE8;&#x610F;&#x62A5;&#x5934;&#x4FE1;&#x606F;&#x548C;&#x90AE;&#x4EF6;&#x6B63;&#x6587;&#x4E4B;&#x95F4;&#x8981;&#x7A7A;&#x4E00;&#x884C;
  utl_smtp.write_data(v_conn,
                      utl_tcp.crlf);

  utl_smtp.write_raw_data(v_conn,
                          utl_raw.cast_to_raw(convert(p_message,
                                                      &apos;ZHS16GBK&apos;)));
  --&#x5199;&#x5165;&#x6B63;&#x6587;&#x7ED3;&#x675F;

  --&#x5173;&#x95ED;&#x6D41;&#x5E76;&#x53D1;&#x9001;&#x90AE;&#x4EF6;,&#x8FD4;&#x56DE;&#x72B6;&#x6001;
  l_reply := utl_smtp.close_data(v_conn);

  --&#x5173;&#x95ED;SMTP&#x8FDE;&#x63A5;
  --CLOSE_CONNECTION&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x5173;&#x95ED;SMTP&#x8FDE;&#x63A5;&#xFF0C;&#x4F46;&#x4F1A;&#x5BFC;&#x81F4;&#x6574;&#x4E2A;SMTP&#x7EC8;&#x6B62;&#xFF0C;&#x53EF;&#x7528;&#x6765;&#x53D6;&#x6D88;&#x7535;&#x5B50;&#x90AE;&#x4EF6;&#x7684;&#x53D1;&#x9001;&#xFF0C;&#x4F46;&#x6B63;&#x5E38;&#x505C;&#x6B62;&#x5E94;&#x4F7F;&#x7528;quit
  utl_smtp.quit(v_conn);

  --&#x663E;&#x793A;&#x8FD4;&#x56DE;&#x4FE1;&#x606F;
  dbms_output.put_line(&apos;&#x72B6;&#x6001;&#x7801;&#xFF1A;&apos; || l_reply.code); --250&#x4E3A;&#x6B63;&#x5E38;
  dbms_output.put_line(&apos;&#x8FD4;&#x56DE;&#x4FE1;&#x606F;&#xFF1A;&apos; || l_reply.text);
EXCEPTION
  WHEN utl_smtp.transient_error
       OR utl_smtp.permanent_error THEN
    BEGIN
      utl_smtp.quit(v_conn);
    EXCEPTION
      WHEN utl_smtp.transient_error
           OR utl_smtp.permanent_error THEN
        NULL; --&#x5F53;SMTP&#x670D;&#x52A1;&#x5668;&#x5173;&#x95ED;&#x6216;&#x4E0D;&#x53EF;&#x7528;&#x65F6;&#xFF0C;&#x8C03;&#x7528;quit&#x5F15;&#x53D1;&#x7684;&#x5F02;&#x5E38;&#x53EF;&#x4EE5;&#x5FFD;&#x7565;
    END;
    dbms_output.put_line(&apos;&#x9519;&#x8BEF;&#x4EE3;&#x7801;&apos; || SQLCODE); --&#x5F53;&#x524D;&#x4F1A;&#x8BDD;&#x6267;&#x884C;&#x72B6;&#x6001;&#xFF0C;&#x9519;&#x8BEF;&#x7F16;&#x7801;
    dbms_output.put_line(&apos;&#x9519;&#x8BEF;&#x4FE1;&#x606F;&apos; || SQLERRM); --&#x5F53;&#x524D;&#x9519;&#x8BEF;&#x4FE1;&#x606F;
    raise_application_error(-20000,
                            &apos;&#x90AE;&#x4EF6;&#x53D1;&#x9001;&#x5931;&#x8D25;&#xFF0C;&#x539F;&#x56E0;&#x5982;&#x4E0B;&#xFF1A; &apos; || SQLERRM);
END;
</code></pre>
<p><img src="img/1571710164822.png" alt="1571710164822"></p>
<p><img src="img/1571709112494.png" alt="1571709112494"></p>
<h2 id="&#x4E09;&#x3001;&#x5E26;&#x9644;&#x4EF6;">&#x4E09;&#x3001;&#x5E26;&#x9644;&#x4EF6;</h2>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="013_死锁.html" class="navigation navigation-prev " aria-label="Previous page: 013_死锁">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="015_转义字符.html" class="navigation navigation-next " aria-label="Next page: 015_转义字符">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"014_邮件发送","level":"1.5.14","depth":2,"next":{"title":"015_转义字符","level":"1.5.15","depth":2,"path":"004_Oracle/015_转义字符.md","ref":"004_Oracle/015_转义字符.md","articles":[]},"previous":{"title":"013_死锁","level":"1.5.13","depth":2,"path":"004_Oracle/013_死锁.md","ref":"004_Oracle/013_死锁.md","articles":[]},"dir":"ltr"},"config":{"plugins":["github","splitter","-lunr","-search","search-plus","simple-page-toc","copy-code-button","page-toc-button","back-to-top-button","chapter-fold","auto-scroll-table","-sharing","livereload"],"root":".","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"chapter-fold":{},"github":{"url":"https://github.com/xiajiajinxuan"},"livereload":{},"simple-page-toc":{"maxDepth":3,"skipFirstH1":false},"splitter":{},"auto-scroll-table":{},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"page-toc-button":{"maxTocDepth":2,"minTocSize":2},"back-to-top-button":{},"copy-code-button":{},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"search-plus":{}},"theme":"default","author":"xiajiajinxuan","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"瑕家瑾轩_Note","language":"zh-hans","gitbook":"*","description":"瑕家瑾轩_Note"},"file":{"path":"004_Oracle/014_邮件发送.md","mtime":"2020-07-06T07:16:46.425Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-08-17T07:13:06.707Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-page-toc-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-auto-scroll-table/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

